// 布尔类型
// let bool: boolean = true
let bool : boolean
bool = false

// 数值类型
let num: number = 123
num = 0b1111011  // 二进制
num = 0o173 // 八进制
num = 0x7b  // 十六进制

// 字符串类型
let str: string
str = 'abc'
str = `数值是${num}`
// console.log(str)

// 数组类型
let arr1: number[]
arr1 = [5]
let arr2: Array<number>
arr2 = [3]
let arr3: (string | number)[]
arr3 = [1, 'a']

// 元组类型
let tuple: [string, number, boolean]
tuple = ['a', 1, false]

// 枚举类型  生成序列号
enum Roles {
  SUPER_ADMIN = 1,  // 可以设置，如果不设置就是从0开始
  ADMIN,
  USER
}

console.log(Roles.SUPER_ADMIN)   // 1

// any类型  任意类型
let value: any
value = 'abc'
value = 123

// void类型 (undefined || null )
const consoleText = (text: string): void => {
  console.log(text)
}
let v: void
v = undefined

consoleText('aaa')

// null 和 undefined
let u: undefined
u = undefined

let n: null
n = null

// nerver 类型
const errorFunc = (message: string): never => {
  throw new Error(message)
}

const infiniteFunc = (): never => {
  while(true){}
}

// let neverVarable = (() => {
//   while(true){}
// })()
// num = neverVarable

// object
let obj = {
  name: 'lison'
}

let obj2 = obj
obj2.name = 'L'
console.log(obj)
function getObject(obj: object): void {
  console.log(obj)
}

getObject(obj2)

// 类型断言
const getLength = (target: string | number): number => {
  if ((<string>target).length || (target as string).length === 0) {
    return (<string>target).length
  } else {
    return target.toString().length
  }
}

getLength(123)
